package br.com.projeto.teste;

import java.sql.Connection;
import java.sql.SQLException;

import br.com.projeto.dao.jdbc.ActorDao;
import br.com.projeto.dao.jdbc.AddressDao;
import br.com.projeto.dao.jdbc.CategoryDao;
import br.com.projeto.dao.jdbc.CityDao;
import br.com.projeto.dao.jdbc.ConnectionFactory;
import br.com.projeto.dao.jdbc.CountryDao;
import br.com.projeto.dao.jdbc.CustomerDao;
import br.com.projeto.dao.jdbc.FilmDao;
import br.com.projeto.dao.jdbc.FilmTextDao;
import br.com.projeto.dao.jdbc.InventoryDao;
import br.com.projeto.dao.jdbc.LanguageDao;
import br.com.projeto.dao.jdbc.PaymentDao;
import br.com.projeto.dao.jdbc.RentalDao;
import br.com.projeto.dao.jdbc.StaffDao;
import br.com.projeto.dao.jdbc.StoreDao;
import br.com.projeto.sakila.bean.TempoRelatorio;

public class ChamadaJdbc {
	
	Connection connection;
	TempoRelatorio tempoRelatorioJdbc;
	
	public TempoRelatorio iniciarConsulta(){
		
		tempoRelatorioJdbc = new TempoRelatorio();
		
		long tempoInicialConnection = System.currentTimeMillis();
		connection = new ConnectionFactory().getConnection();
		long tempoFinalConnection = System.currentTimeMillis(); 
		long tempoConnection = tempoFinalConnection - tempoInicialConnection;
		tempoRelatorioJdbc.setConnection(tempoConnection);
		
		//---------------------------------------------------------------
		
		ActorDao actorDao = new ActorDao();
		tempoRelatorioJdbc.setActor(actorDao.buscarActor(connection));

		AddressDao addressDao = new AddressDao();
		tempoRelatorioJdbc.setAddress(addressDao.buscarAddress(connection));
		
		CategoryDao categoryDao = new CategoryDao();
		tempoRelatorioJdbc.setCategory(categoryDao.buscarCategory(connection));
		
		CityDao cityDao = new CityDao();
		tempoRelatorioJdbc.setCity(cityDao.buscarCity(connection));
		
		CountryDao countryDao = new CountryDao();
		tempoRelatorioJdbc.setCountry(countryDao.buscarCountry(connection));
		
		CustomerDao customerDao = new CustomerDao();
		tempoRelatorioJdbc.setCustomer(customerDao.buscarCustomer(connection));
		
		FilmDao filmDao = new FilmDao();
		tempoRelatorioJdbc.setFilm(filmDao.buscarFilm(connection));
		
		FilmTextDao filmTextDao = new FilmTextDao();
		tempoRelatorioJdbc.setFilmText(filmTextDao.buscarFilmText(connection));
		
		InventoryDao inventoryDao = new InventoryDao();
		tempoRelatorioJdbc.setInventory(inventoryDao.buscarInventory(connection));
		
		LanguageDao languageDao = new LanguageDao();
		tempoRelatorioJdbc.setLanguage(languageDao.buscarLanguage(connection));
		
		PaymentDao paymentDao = new PaymentDao();
		tempoRelatorioJdbc.setPayment(paymentDao.buscarPayment(connection));
		
		RentalDao rentalDao = new RentalDao();
		tempoRelatorioJdbc.setRental(rentalDao.buscarRental(connection));
		
		StaffDao staffDao = new StaffDao();
		tempoRelatorioJdbc.setStaff(staffDao.buscarStaff(connection));
		
		StoreDao storeDao = new StoreDao();
		tempoRelatorioJdbc.setStore(storeDao.buscarStore(connection));
		
		//--------------------------------------------------------------
		
		//Fecha conexao
		try {
			connection.close();
		} catch (SQLException exception) {
			System.err.println("Erro JDBC ao fechar conexao" + exception);
			throw new RuntimeException(exception);
		}
		
		return tempoRelatorioJdbc;
	}

}
